var http = require('../../utils/http.js');
var unionid = wx.getStorageSync('thisCode');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        proRrr: [{
            img: http.imgUrl + 'index_ico4.png',
            text: '积分',
            num: '加载中...',
            btn: 'inteNav'
        }, {
            img: http.imgUrl + 'index_ico6.png',
            text: '余额',
            num: '加载中...',
            btn: 'blanceNav'
        }],
        proRrr1: [{
            img: http.imgUrl + 'index_ico5.png',
            text: '优惠券',
            num: '加载中...',
            btn: 'couponNav'
        }, {
            img: http.imgUrl + 'index_ico7.png',
            text: '充值',
            num: '充值有礼',
            btn: 'rechNav'
        }],
        footArr: [{
            img: http.imgUrl + 'index_ico10.png',
            text: '礼品卡',
            btn: 'giftNav',
            showNav:1,
        }, {
            img: http.imgUrl + 'index_ico9.png',
            text: '附近门店',
            btn: 'nearNav'
        }, {
            img: http.imgUrl + 'index_ico8.png',
            text: '会员权益',
            btn: 'manNav'
        }],
        imgUrl: http.imgUrl,
        showPageFlag: false,
        indexImgs: ['/images/index_banner1.png', '/images/index_nobg.jpg'],
        navData:{}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let nowSDKVersion = wx.getSystemInfoSync().SDKVersion;
        if (http.compareVersion(nowSDKVersion, '1.4.0') == -1) {
            http.showModal('您的微信基础版本库过低，请升级微信或使用原版微信进行体验！', false, () => {
                wx.redirectTo({
                    url: '/pages/index/reaSon/reaSon'
                })
            })
            return
        }

    },
    // 前往积分页面
    inteNav() {
        // http.showModal('敬请期待！',false,()=>{})
        wx.navigateTo({
            url: '/pages/integral/integral'
        })
    },
    // 余额页面
    blanceNav() {
        wx.navigateTo({
            url: '/pages/balance/balance'
        })
    },
    // 优惠券页面
    couponNav() {
        wx.navigateTo({
            url: '/pages/cardBag/cardBag'
        })
    },
    // 充值页面
    rechNav() {
        wx.navigateTo({
            url: '/pages/recharge/recharge'
        })
    },
    // 礼品卡页面
    giftNav() {
        let nowSDKVersion = wx.getSystemInfoSync().SDKVersion;
        if (http.compareVersion(nowSDKVersion, '2.0.7') == -1) {
            http.showModal('抱歉！您的微信版本过低，暂不支持跳转', false, () => {})
            return
        }
    },
    // 附近门店
    nearNav() {
        wx.navigateTo({
            url: '/pages/nearStore/nearStore'
        })
    },
    // 会员权益
    manNav() {
        http.showModal('敬请期待！',false,()=>{})
        // wx.navigateTo({
        //     url: '/pages/integral/integralCenter/integralCenter'
        // })
    },
    // 二维码页面
    ewmNav() {
        wx.navigateTo({
            url: '/pages/payewm/payewm?type=2'
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        wx.hideShareMenu();
        var unionid = wx.getStorageSync('thisCode');
        if (!unionid) {
            wx.reLaunch({
                url: '/pages/userPower/userPower'
            })
        } else {
            this.indexFn(unionid)
        }
    },
    indexFn(unionid) {
        this.setData({ showPageFlag: false })
        console.log(unionid)
        wx.showLoading({ title: '加载中...', })
        http._post('Member/my_info', { unionid: unionid }, res => {
            let data = res.data;
            if (data.status == 1) {
                let proRrr = this.data.proRrr;
                let proRrr1 = this.data.proRrr1;
                proRrr[0].num = data.info.card_point_balance;
                proRrr[1].num = '¥' + data.info.card_balance;
                proRrr1[0].num = data.info.card_coupon_num;
                this.setData({
                    userInfo: data.info,
                    proRrr: proRrr,
                    proRrr1: proRrr1,
                    showPageFlag: true
                })
            } else {
                http.showModal(data.info, false, () => {})
            }
        }, res => {})
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        this.onShow()
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },
})